package likouJava;

public class 将有序数组转换为二叉搜索树 {
    public TreeNode sortedArrayToBST(int[] nums) {
        return buildTree(nums, 0, nums.length -1);
    }

    private TreeNode buildTree(int[] nums, int left, int right) {
        if (left > right)return null;

        int mid = left + (right - left) / 2;

        TreeNode node = new TreeNode(nums[mid]);

        //递归构建左右子树
        node.left = buildTree(nums, left, mid - 1);
        node.right = buildTree(nums, mid + 1, right);

        return node;
    }


}
